package com.controller;

import com.pojo.TbUsers;
import com.service.UsersService;
import com.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/users")
public class UsersController {
    @Autowired
    JSONResult jsonResult;
    @Autowired
    UsersService userService;

    /**
     *
     * @param page 当前页码
     * @param limit  每页条数
     * @param userName 客户名称
     * @return
     */
    @GetMapping("/findAllUserByUserName")
    public JSONResult findAllUserByUserName(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "userName",defaultValue = "") String userName){
        return userService.findAllUserByUserName(page,limit,userName);
    }

    @GetMapping("/findAllUser")
    public JSONResult findAllUser(@RequestParam("page") int page,@RequestParam("limit") int limit){
        return userService.findAllUser(page,limit);
    }

    /**
     *
     * @param page
     * @param limit
     * @param state 客户状态 1(启用)/0(禁用)
     * @return
     */
    @GetMapping("/findAllUserByState")
    public JSONResult findAllUserByState(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam(value = "state",defaultValue = "-1") int state){
        return userService.findAllUserByState(page,limit,state);
    }

    /**
     * @param user 客户对象实体
     * @return
     */
    @PostMapping("/addUser")
    public JSONResult addUser(@RequestBody TbUsers user){
        return userService.addUser(user);
    }

    /**
     * @param userId 客户id(唯一标识)
     * @return
     */
    @GetMapping("/deleteUser")
    public JSONResult deleteUser(@RequestParam("userId") int userId){
        return userService.deleteUser(userId);
    }

    /**
     * @param user 客户对象实体
     * @return
     */
    @PostMapping("/updateUser")
    public JSONResult updateUser(@RequestBody TbUsers user){
        return userService.updateUser(user);
    }

    /**
     * @param userId 客户id(唯一标识)
     * @return
     */
    @GetMapping("/findUserById")
    public JSONResult findUserById(@RequestParam("userId")int userId){
        return userService.findUserById(userId);
    }
}
